import { logger } from '../utils/logger';
import { Card } from '../card/base/Card';
import { events } from '../utils/events';
import { Room } from '../api/Room';

export namespace CardRegistry {
	const cards = new Map<string, new (id: string) => Card>();

	/**
	 * 注册卡牌
	 * @param id
	 * @param card
	 */
	export function register(id: string, card: new (id: string) => Card) {
		cards.set(id, card);
		logger.info(`RegisterCard: ${id}`);
	}

	/**
	 * 获取卡牌
	 * @param id
	 * @returns
	 */
	export function get(id: string) {
		const card = cards.get(id);
		if (!card) return;
		return new card(id);
	}

	/**
	 * 添加到卡池
	 * @param name
	 * @param cardId
	 * @param count
	 */
	export function addPool(name: string, cardId: string, count: number = 1) {
		events.on('roomInit', (room: Room) => {
			room.pools.add(name, cardId, count);
			// TODO: 临时
			if (name != 'global') room.pools.add('global', cardId, count);
		});
	}
}
